﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using Spring.Data.Common;
using System.Data;
using Spring.Data.Generic;
using Infrastructure;

namespace RepositoryMSSQL
{
    public class TemplateRepository
    {
        private static string strBase = "select entry_id, function_mapping_id, step_no, version_id, flow, seq, name, description, data_type, "
                + " data_type_mapping_id, is_mandatory, dependency, dependency_value, assignment_type, required_by, is_UWL, "
                + " application_step_code, application_create_step, status_group, last_modified_date, last_modified_by, require_progress "
                + " from WorkFlowTemplates ";

        //public static IList<WorkflowTemplate> ListTemplates()
        //{
        //    string strSql = strBase;
        //    //IDbParameters para = DBHelper.SpringDBTemplate.CreateDbParameters();
        //    //para.Add("FunctionMappingID", DbType.Int64).Value = FunctionMappingID;
        //    //para.Add("stepNo", DbType.String).Value = category + "%";
        //    //para.Add("versionId", DbType.Int64).Value = versionId;

        //    return DBHelper.SpringDBTemplate.QueryWithRowMapperDelegate(CommandType.Text, strSql,
        //        new RowMapperDelegate<WorkflowTemplate>(MapRow));
        //}

        //private static WorkflowTemplate MapRow(IDataReader dr, int rownumber)
        //{
        //    WorkflowTemplate obj = new WorkflowTemplate();

        //    obj.EntryID = dr.IsDBNull(0) ? -1 : dr.GetInt64(0);
        //    obj.FunctionMappingID = dr.IsDBNull(1) ? -1 : dr.GetInt64(1);
        //    obj.StepNo = dr.IsDBNull(2) ? string.Empty : dr.GetString(2);
        //    obj.VersionID = dr.IsDBNull(3) ? -1 : dr.GetInt64(3);
        //    obj.Flow = dr.IsDBNull(4) ? 0 : dr.GetInt32(4);
        //    obj.Seq = dr.IsDBNull(5) ? -1 : dr.GetDouble(5);
        //    obj.Name = dr.IsDBNull(6) ? string.Empty : dr.GetString(6);
        //    obj.Description = dr.IsDBNull(7) ? string.Empty : dr.GetString(7);
        //    string s = dr.GetString(8);
        //    if (!string.IsNullOrEmpty(dr.GetString(8).Trim()))
        //        //obj.DataType = (InternalDataType)Enum.Parse(typeof(InternalDataType), dr.GetString(8), true);
        //        obj.Name = dr.IsDBNull(8) ? string.Empty : dr.GetString(8);
        //    obj.DataTypeMappingID = dr.IsDBNull(9) ? -1 : dr.GetInt32(9);
        //    obj.IsMandatory = dr.IsDBNull(10) ? false : dr.GetBoolean(10);
        //    obj.Dependency = dr.IsDBNull(11) ? string.Empty : dr.GetString(11);
        //    obj.DependencyValue = dr.IsDBNull(12) ? string.Empty : dr.GetString(12);
        //    obj.AssignmentType = dr.IsDBNull(13) ? string.Empty : dr.GetString(13);
        //    obj.RequiredBy = dr.IsDBNull(14) ? string.Empty : dr.GetString(14);
        //    string isUwl = dr.IsDBNull(15) ? String.Empty : dr.GetString(15);
        //    obj.IsUwl = (String.IsNullOrEmpty(isUwl.Trim())) ? false : Convert.ToBoolean(Convert.ToInt32(isUwl));
        //    obj.ApplicationStepCode = dr.IsDBNull(16) ? string.Empty : dr.GetString(16);
        //    obj.ApplicationCreateStep = dr.IsDBNull(17) ? string.Empty : dr.GetString(17);
        //    obj.StatusGroup = dr.IsDBNull(18) ? string.Empty : dr.GetString(18);
        //    obj.LastModifiedDate = dr.IsDBNull(19) ? DateTime.MinValue : dr.GetDateTime(19);
        //    obj.LastModifiedBy = dr.IsDBNull(20) ? string.Empty : dr.GetString(20);
        //    obj.RequireProgress = dr.IsDBNull(21) ? false : dr.GetBoolean(21);

        //    return obj;
        //}
    }
}
